﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AliyunOpenSearch4Net.Search
{
    /// <summary>
    /// Search summary
    /// </summary>
    public class SearchSummary
    {
        /// <summary>
        /// Gets or sets the summary field.
        /// </summary>
        /// <value>
        /// The summary field.
        /// </value>
        public string Field { get; set; }

        /// <summary>
        /// Gets or sets the summary element.
        /// </summary>
        /// <value>
        /// The summary element.
        /// </value>
        public string Element { get; set; }

        /// <summary>
        /// Gets or sets the summary ellipsis.
        /// </summary>
        /// <value>
        /// The summary ellipsis.
        /// </value>
        public string Ellipsis { get; set; }

        /// <summary>
        /// Gets or sets the summary snipped.
        /// </summary>
        /// <value>
        /// The snipped.
        /// </value>
        public int Snipped { get; set; }

        /// <summary>
        /// Gets or sets the summary length.
        /// </summary>
        /// <value>
        /// The summary length.
        /// </value>
        public int Len { get; set; }

        /// <summary>
        /// Gets or sets the summary prefix.
        /// </summary>
        /// <value>
        /// The summary prefix.
        /// </value>
        public string Prefix { get; set; }

        /// <summary>
        /// Gets or sets the summary postfix.
        /// </summary>
        /// <value>
        /// The summary postfix.
        /// </value>
        public string Postfix { get; set; }

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            var value = "summary_field:" + Field;

            if (!string.IsNullOrEmpty(Element))
                value += ",summary_element:" + Element;

            if (!string.IsNullOrEmpty(Ellipsis))
                value += ",summary_ellipsis:" + Ellipsis;

            if (Snipped > 0)
                value += ",summary_snipped:" + Snipped;

            if (Len > 0)
                value += ",summary_len:" + Len;

            if (!string.IsNullOrEmpty(Prefix))
                value += ",summary_prefix:" + Prefix;

            if (!string.IsNullOrEmpty(Postfix))
                value += ",summary_postfix:" + Postfix;

            return value;
        }
    }
}
